7.8 Plotter interaction

At times, it is convenient to use the state of the plotter as feedback to plotted expressions. This kind of feedback has been seen before, in §7.6, where axis domains were introduced. These are described further here, along with axis variables and a clipping function.

As seen in Figure §7.10 an axis domain generates a sequence of values running from one end of an axis to the other in small steps that can be used to plot line segments. Axis domains are accessed using the simple notation x∈𝕏 and y∈𝕐 in domain expressions.

The ends of the axes can be changed in the plotter. For some plotted functions, it may be desirable to somehow bind the function to the axes so the plot can reflect changes in the axes. This is accommodated by making the ends of the axes available via the axis-end variables 𝕏__- and 𝕏__+ along with 𝕐__- and 𝕐__+. Like the variables 𝕏 and 𝕐 used in domain expressions, the axis-end variables are only made available for binding in the plotter.

Another facility that interacts with the state of the plotter is a special line function that draws a line clipped to the region defined by the axes. This is not always necessary because many plots are composed of small line segments that are clipped by simply comparing their two end-points to the plot region. But for a general line where only the segment that crosses the plot region is to be viewed, the line-clipping function is used to constrain the displayed segment. That is, only points that fall within the region bounded by the lines x=𝕏__-, x=𝕏__+, y=𝕐__- and y=𝕐__+ should be displayed.

The line-clipping function is parameterized by two row vectors. The first defines a point on the line. The second provides the line's attitude. Together, the point and the attitude provide a parametric specification of a line. For example, the line (x, y)ʋ+t⋅(dx, dy)ʋ generates all the points on a line by varying the parameter t. It is possible to discover values of t such that the resulting points lie on the lines that bound the region. (If none do, the line is not within the plot region.) The line function discovers the points of intersection and renders the line as a line segment between the intersections.

The line function is parameterized by a point and an attitude. As a non-trivial example, consider the problem of drawing lines from the family x=y that cross the x-axis at integer intervals. This is accomplished by the expression

(line((x, 0)ʋ, (1, 1)ʋ)|x∈⌊(, ⌈𝕏__-⌉, ⌈𝕐__-⌉)⌋, ⌈(, ⌊𝕏__+⌋, ⌊𝕐__+⌋)⌉).

 


In this expression, the values of the axes end-points are first made integral by truncating towards zero. Then the larger (in magnitude) of the negative x- or y-end points and the positive x- or y-end points are provided as the limits of a generator. Thus x takes on values from, say, -3 to +3. The resulting plot can be seen in Figure 7.14.

Figure 7.14 Lines clipped to the 𝕏- and 𝕐-axes